export function fill_zero(num,n){
  while(num.toString().length<n){
    num="0"+num
  }
  return num.toString();
}
export function price_format(_number,n) {
  if(!isNaN(_number)){
    if(!n){
      return _number;
    }  //比如1.5*0.95的结果是1.4249999999999998 用一次四舍五入不能取到正确值
    let number1= Number((Math.round((Math.round(_number*Math.pow(10,n+5))/Math.pow(10,n+5))*Math.pow(10,n))/Math.pow(10,n)));
    return number1.toFixed(n);
  }else{
    return false;
  }
}

let arr=[]
let index=0
let stop
export function fang_pin(time,fun) {
  arr[index]=new Date().getTime()
  if(arr[index]-arr[index-1]<time){
    clearInterval(stop)
  }
  stop= setTimeout(()=>{
    fun()
  },time+2)
  index++
}
export function stop_slider(e,scrollEle,touchStart) {
  let newTouchY=e.touches[0].pageY
  let newTouchX=e.touches[0].pageX
  let isTouchY=Math.abs(newTouchX-touchStart.X)<Math.abs(newTouchY-touchStart.Y)
      if(scrollEle.scrollTop<1&&isTouchY){
         if(newTouchY>touchStart.Y){
            console.log(1)
          e.preventDefault()
           return false
        }
      }
      if(scrollEle.scrollHeight-scrollEle.clientHeight<=scrollEle.scrollTop&&isTouchY){
        if(newTouchY<touchStart.Y){
          console.log(1)
          e.preventDefault()
          return false
        }
      }

}
export function stop_sliderX(e,scrollEle,touchStart) {
  let newTouchX=e.touches[0].pageX
  let newTouchY=e.touches[0].pageY
  let isTouchX=Math.abs(newTouchX-touchStart.X)>Math.abs(newTouchY-touchStart.Y)

      if(scrollEle.scrollLeft<1&&isTouchX){
         if(newTouchX>touchStart.X){
            console.log(1)
          e.preventDefault()
           return false
        }
      }
      if(scrollEle.scrollWidth-scrollEle.clientWidth<=scrollEle.scrollLeft&&isTouchX){
        if(newTouchX<touchStart.X){
          console.log(1)
          e.preventDefault()
          return false
        }
      }

}
